<?php

namespace App\V3\V3_2_6\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class PictureAlbumModel extends Model
{


    use HasFactory;
    const    PAGESIZE  = 20;
    protected $table   = 'picture_album';

    /**
     * $dates 数组内的列转换为日期格式
     *
     * @var array
     */
    /**
     * 新建图片画册
     */
    static public function addPictureAlbum($data){

        return PictureAlbumModel::insertGetId($data);
    }

    /**
     * 查询图片画册信息
     *
     */
    static public function getPictureAlbumInfo($condition){

        return PictureAlbumModel::where($condition)->first();
    }
    static public function getPictureAlbumInfos($condition,$pa_id_arr){

        return PictureAlbumModel::select('id','album_cover_img','background_music','main_id')
        ->where($condition)->whereIn('id',$pa_id_arr)->get()->toArray();
    }
    /**
     * 修改图片画册信息
     *
     */
    static public function updateAlbumImgs($condition,$data){

        $data['update_time'] = time();

        return PictureAlbumModel::where($condition)->update($data);
    }
    /**
     * 删除图片画册信息
     *
     */
    static public function delPictureAlbum($condition,$pa_id_arr){

     return PictureAlbumModel::where($condition)->whereIn('id',$pa_id_arr)->delete();
    }
    /**
     * 图片画册列表
     */
    static public function getPictureAlbumList($condition,$currentPage,$pageSize){

        return  PictureAlbumModel::select('pa.*')->from('picture_album AS pa')
        ->leftJoin('admin AS ad', 'pa.user_id', '=', 'ad.id')
        ->where($condition)
        ->orderBy('pa.create_time', 'DESC')
        ->paginate($pageSize,['*'], '',$currentPage)
        ->toArray();

    }
}
